package com.wang.springframework.test.bean;

import net.sf.cglib.proxy.MethodProxy;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

import java.lang.reflect.Method;

/**
 * @author wangjianhua
 * @Description
 * @date 2021/9/1/001 21:20
 */
public class UserServiceInterceptor implements MethodInterceptor {


    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        long start = System.currentTimeMillis();
        try
        {
            return invocation.proceed();
        }
        finally
        {
            System.out.println("监控开始: By Aop");
            System.out.println("方法名称:"+invocation.getMethod());
            System.out.println("方法耗时:"+(System.currentTimeMillis()-start)+"ms");
            System.out.println("监控结束: END \r\n");
        }
    }
}
